/**
 * Created by KGL on 2015/8/19.
 */
function rolesSet(id){
    $('#authRoleModel').modal('show');
    $("#roleListTable").jqGrid({
        url: "/gouda-backend/systemRole/getSystemAvailableRoles",
        datatype: "json", //数据来源，本地数据
        jsonReader: {
            root: "pageModel.data",
            page: "pageModel.currentPage",
            total: "pageModel.totalPages",
            records: "pageModel.totalRows",
            repeatitems: false
        },
        colNames: ['roleId', '角色编号', '角色名称'],
        colModel: [
            {name:'roleId',index: 'roleId', hidden : true},
            {name: 'roleCode', index: 'roleCode', width:'270px', align: 'center'},
            {name: 'roleName', index: 'roleName', width:'270px', align: "center"}
        ],
        height: "auto",
        //autowidth: true,
        rowNum: 10,
        rowList: [10],
        pager: '#gridPager',
        multiselect: true,
        viewrecords: true,
        scrollcols: false,
        prmNames: {page: "pageNum", rows: "pageSize"}
    }).navGrid("#gridPager",{edit:false,add:false,del:false,search:false});
    $("#authUserId").val(id);
    $("#roleListTable").trigger("reloadGrid");
    $("#roleListTable").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden"});
}

function saveAuthRoles(){
    var ids = $("#roleListTable").jqGrid('getGridParam','selarrrow');
    var roleIds = "";
    for(i in ids){
        var rowData = $("#roleListTable").jqGrid('getRowData', ids[i]);
        roleIds += rowData.roleId + ",";
    }
    if(roleIds.length > 0){
        roleIds = roleIds.substring(0, roleIds.length-1);
        $("#rolesStr").val(roleIds);
        var param = {url: '../../systemUser/authUser', async: false};
        param.data = JSON.stringify($('#authRoleModel form').serializeObject());
        param.sucFn = function(data){
            if (data.code == '1') {
                $('#authRoleModel').modal('hide');
                $("#list4").trigger("reloadGrid");
            } else {
                alert('保存失败!错误信息：' + data.msg);
            }
        };
        requestJSON(param);
    }
}